from goods.models import SPU, Brand, GoodsCategory
from rest_framework import serializers


# spu信息序列化器
class SPUViewSetSerializer(serializers.ModelSerializer):

    # 重写品牌名称
    brand = serializers.StringRelatedField(read_only=True)
    brand_id = serializers.IntegerField()

    category1 = serializers.StringRelatedField(read_only=True)
    category1_id = serializers.IntegerField()

    category2 = serializers.StringRelatedField(read_only=True)
    category2_id = serializers.IntegerField()

    category3 = serializers.StringRelatedField(read_only=True)
    category3_id = serializers.IntegerField()



    class Meta:
        model = SPU
        fields = "__all__"




# 品牌序列化器
class SPUSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        fields = ("id", "name")


# 分类序列化器
class SPUCategoriesSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields = ("id", "name")

